<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="ZhangPing">





<title>Flutter--ListView组件 | ZhangPing&#39;s Blog</title>



    <link rel="icon" href="/favicon.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    



    
    
        
    


<meta name="generator" content="Hexo 4.2.0"></head>
<body>
    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">ZhangPing&#39;s Blog</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">ZhangPing&#39;s Blog</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/archives">Posts</a>
                
                    <a class="menu-item" href="/category">Categories</a>
                
                    <a class="menu-item" href="/tag">Tags</a>
                
                    <a class="menu-item" href="/about">About</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
        <div class="main">
            <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    document.ready(
        function () {
            tocbot.init({
                tocSelector: '.tocbot-list',
                contentSelector: '.post-content',
                headingSelector: 'h1, h2, h3, h4, h5',
                collapseDepth: 1,
                orderedList: false,
                scrollSmooth: true,
            })
        }
    )

    function expand_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 6,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "collapse_toc()");
        b.innerHTML = "Collapse all"
    }

    function collapse_toc() {
        var b = document.querySelector(".tocbot-toc-expand");
        tocbot.init({
            tocSelector: '.tocbot-list',
            contentSelector: '.post-content',
            headingSelector: 'h1, h2, h3, h4, h5',
            collapseDepth: 1,
            orderedList: false,
            scrollSmooth: true,
        });
        b.setAttribute("onclick", "expand_toc()");
        b.innerHTML = "Expand all"
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">Flutter--ListView组件</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/">ZhangPing</a>
                    

                    
                        <span class="post-time">
                        Date: <a href="#">February 8, 2020&nbsp;&nbsp;20:00:00</a>
                        </span>
                    
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Flutter/">Flutter</a>
                            
                        </span>
                    
                </div>
            
        </header>

        <div class="post-content">
            <h2 id="一、Flutter-列表组件概述"><a href="#一、Flutter-列表组件概述" class="headerlink" title="一、Flutter 列表组件概述"></a>一、Flutter 列表组件概述</h2><p>Flutter 中我们可以通过 ListView 来定义列表项，支持垂直和水平方向展示。通过一个属性就可以控制列表的显示方向。列表有以下分类：<br>1、垂直列表<br>2、垂直图文列表<br>3、水平列表<br>4、动态列表<br>5、矩阵式列表</p>
<h2 id="二、Flutter-列表参数"><a href="#二、Flutter-列表参数" class="headerlink" title="二、Flutter 列表参数"></a>二、Flutter 列表参数</h2><table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>scrollDirection</td>
<td>Axis</td>
<td>Axis.horizontal 水平列表 <br> Axis.vertical 垂直列表</td>
</tr>
<tr>
<td>padding</td>
<td>EdgeInsetsGeometry</td>
<td>内边距</td>
</tr>
<tr>
<td>resolve</td>
<td>bool</td>
<td>组件反向排序</td>
</tr>
<tr>
<td>children</td>
<td>List<Widget></td>
<td>列表元素</td>
</tr>
</tbody></table>
<h2 id="三、Flutter-基本列表"><a href="#三、Flutter-基本列表" class="headerlink" title="三、Flutter 基本列表"></a>三、Flutter 基本列表</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">classHomeContentextendsStatelessWidget&#123; </span><br><span class="line">	<span class="meta">@override</span> </span><br><span class="line">	Widgetbuild(BuildContextcontext)&#123; <span class="comment">//<span class="doctag">TODO:</span>implementbuild </span></span><br><span class="line">		returnCenter( </span><br><span class="line">			child:ListView( </span><br><span class="line">				children:&lt;Widget&gt;[ </span><br><span class="line">					ListTile( </span><br><span class="line">						leading:Icon(Icons.phone), </span><br><span class="line">						title:Text(<span class="string">"thisislist"</span>,style:TextStyle(fontSize:<span class="number">28.0</span>),), </span><br><span class="line">						subtitle:Text(<span class="string">'thisislistthisislist'</span>), </span><br><span class="line">					), </span><br><span class="line">					ListTile(</span><br><span class="line">						title:Text(<span class="string">"thisislist"</span>), </span><br><span class="line">						subtitle:Text(<span class="string">'thisislistthisislist'</span>), </span><br><span class="line">						trailing:Icon(Icons.phone),</span><br><span class="line">					) , </span><br><span class="line">					ListTile( </span><br><span class="line">						title:Text(<span class="string">"thisislist"</span>), </span><br><span class="line">						subtitle:Text(<span class="string">'thisislistthisislist'</span>), </span><br><span class="line">					), </span><br><span class="line">					ListTile( </span><br><span class="line">						title:Text(<span class="string">"thisislist"</span>), </span><br><span class="line">						subtitle:Text(<span class="string">'thisislistthisislist'</span>), </span><br><span class="line">					), </span><br><span class="line">					ListTile( </span><br><span class="line">						title:Text(<span class="string">"thisislist"</span>), </span><br><span class="line">						subtitle:Text(<span class="string">'thisislistthisislist'</span>), </span><br><span class="line">					)</span><br><span class="line">				],</span><br><span class="line">			),</span><br><span class="line">		);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="四、Flutter-水平列表"><a href="#四、Flutter-水平列表" class="headerlink" title="四、Flutter 水平列表"></a>四、Flutter 水平列表</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">classHomeContentextendsStatelessWidget&#123; </span><br><span class="line">	<span class="meta">@override</span> </span><br><span class="line">	Widgetbuild(BuildContextcontext)&#123; </span><br><span class="line">		<span class="comment">//<span class="doctag">TODO:</span>implementbuild </span></span><br><span class="line">		returnContainer( </span><br><span class="line">			height:<span class="number">200.0</span>, </span><br><span class="line">			margin:EdgeInsets.all(<span class="number">5</span>), </span><br><span class="line">			child:ListView( </span><br><span class="line">				scrollDirection:Axis.horizontal, </span><br><span class="line">				children:&lt;Widget&gt;[ </span><br><span class="line">					Container( </span><br><span class="line">						width:<span class="number">180.0</span>, </span><br><span class="line">						color:Colors.lightBlue, </span><br><span class="line">					), </span><br><span class="line">					Container( </span><br><span class="line">						width:<span class="number">180.0</span>, </span><br><span class="line">						color:Colors.amber, </span><br><span class="line">						child:ListView( 	</span><br><span class="line">							children:&lt;Widget&gt;[ </span><br><span class="line">							Image.network( <span class="string">'https://resources.ninghao.org/images/childhood-in-a-picture.jpg'</span> ), </span><br><span class="line">							SizedBox(height:<span class="number">16.0</span>), </span><br><span class="line">							Text(<span class="string">'这是一个文本信息'</span>, </span><br><span class="line">								textAlign:TextAlign.center, </span><br><span class="line">								style:TextStyle( fontSize:<span class="number">16.0</span> ), ) </span><br><span class="line">							], </span><br><span class="line">						), </span><br><span class="line">					), </span><br><span class="line">					Container( </span><br><span class="line">						width:<span class="number">180.0</span>, </span><br><span class="line">						color:Colors.deepOrange, </span><br><span class="line">					), </span><br><span class="line">					Container(</span><br><span class="line">						width:<span class="number">180.0</span>, </span><br><span class="line">						color:Colors.deepPurpleAccent, </span><br><span class="line">					), </span><br><span class="line">				], </span><br><span class="line">			) </span><br><span class="line">		); </span><br><span class="line">	&#125; </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="五、Flutter-动态列表（动态循环数据）"><a href="#五、Flutter-动态列表（动态循环数据）" class="headerlink" title="五、Flutter 动态列表（动态循环数据）"></a>五、Flutter 动态列表（动态循环数据）</h2><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span><span class="string">'package:flutter/material.dart'</span>;</span><br><span class="line">voidmain()=&gt;runApp(MyApp());</span><br><span class="line">	classMyAppextendsStatelessWidget&#123; </span><br><span class="line">		<span class="meta">@override</span> </span><br><span class="line">		Widgetbuild(BuildContextcontext)&#123; </span><br><span class="line">		<span class="comment">//<span class="doctag">TODO:</span>implementbuild </span></span><br><span class="line">		returnMaterialApp( </span><br><span class="line">			home:Scaffold( </span><br><span class="line">			appBar:AppBar(title:Text(<span class="string">'FlutterDemo'</span>)), </span><br><span class="line">			body:HomeContent(), </span><br><span class="line">		)); </span><br><span class="line">	&#125; </span><br><span class="line">&#125; </span><br><span class="line">classHomeContentextendsStatelessWidget&#123; </span><br><span class="line">	Listlist=newList(); </span><br><span class="line">	HomeContent(&#123;Keykey&#125;):<span class="keyword">super</span>(key:key)&#123; </span><br><span class="line">		<span class="keyword">for</span>(vari=<span class="number">0</span>;i&lt;<span class="number">20</span>;i++)&#123; </span><br><span class="line">			list.add(<span class="string">"这是第$&#123;i&#125;条数据"</span>); </span><br><span class="line">		&#125; </span><br><span class="line">		print(list); </span><br><span class="line">	&#125;</span><br><span class="line">	<span class="meta">@override</span> </span><br><span class="line">	Widgetbuild(BuildContextcontext)&#123; </span><br><span class="line">		<span class="comment">//<span class="doctag">TODO:</span>implementbuild</span></span><br><span class="line">		returnListView.builder( </span><br><span class="line">			itemCount:<span class="keyword">this</span>.list.length, </span><br><span class="line">			itemBuilder:(context,index)&#123; </span><br><span class="line">			<span class="comment">//print(context); </span></span><br><span class="line">				<span class="keyword">return</span> ListTile( </span><br><span class="line">					leading:Icon(Icons.phone), </span><br><span class="line">					title:Text(<span class="string">"$&#123;list[index]&#125;"</span>), </span><br><span class="line">				); </span><br><span class="line">			&#125;,</span><br><span class="line">		);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

        </div>

        
            <section class="post-copyright">
                
                    <p class="copyright-item">
                        <span>Author:</span>
                        <span>ZhangPing</span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>Permalink:</span>
                        <span><a href="https://zhangpingv5.gitee.io/2020/02/08/Flutter--ListView%E7%BB%84%E4%BB%B6/">https://zhangpingv5.gitee.io/2020/02/08/Flutter--ListView%E7%BB%84%E4%BB%B6/</a></span>
                    </p>
                
                
                    <p class="copyright-item">
                        <span>License:</span>
                        <span>转载请注明出处</span>
                    </p>
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span>Self-descipline grants me freedom.</span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
                <span>Tag(s):</span>
                <span class="tag">
                    
                    
                        <a href="/tags/Flutter/"># Flutter</a>
                    
                        
                </span>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2020/02/10/Flutter--GridView%E7%BB%84%E4%BB%B6/">Flutter--GridView组件</a>
            
            
            <a class="next" rel="next" href="/2020/02/07/Flutter--Image%E7%BB%84%E4%BB%B6/">Flutter--Image组件</a>
            
        </section>


    </article>
</div>

        </div>
        <footer id="footer" class="footer">
    <div class="copyright">
        <span>© ZhangPing | Powered by <a href="https://hexo.io" target="_blank">Hexo</a> & <a href="https://github.com/Siricee/hexo-theme-Chic" target="_blank">Chic</a></span>
    </div>
</footer>

    </div>
</body>
</html>
